package com.ruoyi.demo1.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demo1.domain.Demo1;
import com.ruoyi.demo1.service.IDemo1Service;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模板Controller
 * 
 * @author ruoyi
 * @date 2024-10-09
 */
@RestController
@RequestMapping("/demo1/demo1")
public class Demo1Controller extends BaseController
{
    @Autowired
    private IDemo1Service demo1Service;

    /**
     * 查询模板列表
     */
    @PreAuthorize("@ss.hasPermi('demo1:demo1:list')")
    @GetMapping("/list")
    public TableDataInfo list(Demo1 demo1)
    {
        startPage();
        List<Demo1> list = demo1Service.selectDemo1List(demo1);
        return getDataTable(list);
    }

    /**
     * 导出模板列表
     */
    @PreAuthorize("@ss.hasPermi('demo1:demo1:export')")
    @Log(title = "模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Demo1 demo1)
    {
        List<Demo1> list = demo1Service.selectDemo1List(demo1);
        ExcelUtil<Demo1> util = new ExcelUtil<Demo1>(Demo1.class);
        util.exportExcel(response, list, "模板数据");
    }

    /**
     * 获取模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('demo1:demo1:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(demo1Service.selectDemo1ById(id));
    }

    /**
     * 新增模板
     */
    @PreAuthorize("@ss.hasPermi('demo1:demo1:add')")
    @Log(title = "模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Demo1 demo1)
    {
        return toAjax(demo1Service.insertDemo1(demo1));
    }

    /**
     * 修改模板
     */
    @PreAuthorize("@ss.hasPermi('demo1:demo1:edit')")
    @Log(title = "模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Demo1 demo1)
    {
        return toAjax(demo1Service.updateDemo1(demo1));
    }

    /**
     * 删除模板
     */
    @PreAuthorize("@ss.hasPermi('demo1:demo1:remove')")
    @Log(title = "模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(demo1Service.deleteDemo1ByIds(ids));
    }
}
